package com.dfbz.homework9;

import com.dfbz.homework10.R;
import com.sun.media.sound.FFT;

import java.io.*;
import java.util.Properties;
public class demo {
    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\admin\\Desktop\\count.txt");
        if(file.exists()){
            //读取文件
            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));
            Properties properties = new Properties();//定义一个集合
            properties.load(inputStreamReader);//讲文件读出来的加载到集合中
            String count = (String) properties.get("count");
            if(count.equals("null")){
                properties.setProperty("count","0");//. 取得count属性，如果count属性为null，则设置count属性为0
            }
            String count1 = properties.get("count").toString();
            int i = Integer.parseInt(count1);
            if(i<3){
                i++;
                properties.put("count",""+(i));
                System.out.println(properties.getProperty("count"));
            }else {
                System.out.println("程序使 用次数已满，请续费");
            }
            //创建一个输出流
            FileWriter fileWriter=new FileWriter(file);
            properties.store(fileWriter,"保存成功");
        }else {
            new File("C:\\Users\\admin\\Desktop\\count.txt").createNewFile();
        }
    }
}
